package com.liuwa.common.bean;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.ArrayList;
import java.util.List;

@ApiModel(value = "Page", description = "分页对象")
public class Page<T> {

    /**
     * 列表
     */
    @ApiModelProperty(value="列表", name="items")
    protected List<T> items = new ArrayList<T>();

    /**
     * 页码
     */
    @ApiModelProperty(value="页码", name="page")
    protected Integer page;

    /**
     * 分页大小
     */
    @ApiModelProperty(value="分页大小", name="size")
    protected Integer size;

    /**
     * 总记录数
     */
    @ApiModelProperty(value="总记录数", name="total")
    protected Long total;

    /**
     * 总页数
     */
    @ApiModelProperty(value="总页数", name="totalPages")
    protected Integer totalPages;


    public Page(){}

    public Page(int page, int size){
        this.page = page;
        this.size = size;
    }

    public List<T> getItems() {
        return items;
    }

    public void setItems(List<T> items) {
        this.items = items;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
        if (size > 0 && total > -1) {
            this.totalPages = (int) (total % size == 0 ? total / size : total / size + 1);
        }
    }

    public Integer getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(Integer totalPages) {
        this.totalPages = totalPages;
    }
}